package com.example.widgetcase.slice.taperchart;

import com.example.widget_lib.utils.PxUtil;
import com.example.widget_lib.widget.taperchart.TaperChart;
import com.example.widgetcase.ResourceTable;
import com.example.widgetcase.slice.BaseSlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.utils.Color;

import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ContrastAbility extends BaseSlice {
    private TaperChart cont_tchart;
    private Button cont_RefeshBtn;

    @Override
    public int getChildUIContent() {
        return ResourceTable.Layout_ability_contrast;
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        initView();
        syncTaperChartData();
    }

    private void initView() {
        cont_tchart = (TaperChart) findComponentById(ResourceTable.Id_cont_tchart);
        cont_tchart.setDrawTopValue(true);
        cont_tchart.setTcMode(4);
        cont_tchart.setInnerSpace((int) PxUtil.vp2px(28f));
        cont_RefeshBtn = (Button) findComponentById(ResourceTable.Id_cont_RefeshBtn);
        cont_RefeshBtn.setClickedListener((component -> {

        }));
    }

    private void syncTaperChartData() {
        int green = Color.rgb(0, 255, 0);
        int darkGray = Color.rgb(128, 128, 128);
        cont_tchart.offSetXy(48f);
        cont_tchart.isShowDebugView(true);
        cont_tchart.setTaperColors(green, darkGray);

        List<String> keys = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            if (i % 2 == 0) {
                keys.add("asdasd");
            } else {
                keys.add("第" + (i + 1) + "次");
            }
        }
        List<Float> values = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            if (i % 2 == 0) {
                values.add(0f);
            } else {
                int randomInt = new SecureRandom().nextInt(100);
                values.add((float) randomInt);
            }
        }
        String[] labels = new String[]{"30min以内", "30-45min", "45min以上"};
        cont_tchart.setData(keys, values, labels);
    }
}
